package my.sample.channel.datagram;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;

public class SocketTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		try {
			// get a datagram socket
			int i = 0;
			DatagramSocket socket = new DatagramSocket();
			while (true) {
				// send request
				byte[] buf = new byte[256];
				InetAddress address = InetAddress.getByName("210.210.122.122");
				DatagramPacket packet = new DatagramPacket(buf, buf.length,
						address, 5555);
				socket.send(packet);
				System.out.println("sending " + i++);
				try {
					Thread.sleep(1);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			/*			// get response
			packet = new DatagramPacket(buf, buf.length);
			socket.receive(packet);
			// display response
			String received = new String(packet.getData(), 0, packet.getLength());
			System.out.println("Quote of the Moment: " + received);*/
//			socket.close();
		} catch (SocketException e) {
			e.printStackTrace();
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
